// @dart=2.9
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_base/common/provider/provider.dart';
import 'package:flutter_base/global.dart';
import 'package:flutter_base/pages/index/index.dart';
import 'package:flutter_base/common/router/routes.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

void main() => Global.init().then((e) => runApp(
  MultiProvider(
    providers: [
      ChangeNotifierProvider<AppState>.value(
        value: Global.appState,
      ),
    ],
    child: Consumer<AppState>(builder: (context, appState, _) {
      if (appState.isGrayFilter) {
        return ColorFiltered(
          colorFilter: ColorFilter.mode(Colors.white, BlendMode.color),
          child: MyApp(),
        );
      } else {
        return MyApp();
      }
    }),
  ),
));

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // 812-44-34
    return ScreenUtilInit(
      designSize: Size(375, 734),
      allowFontScaling: true,
      builder: () => RefreshConfiguration(
        headerBuilder: () => WaterDropHeader(),
        // 配置默认头部指示器,假如你每个页面的头部指示器都一样的话,你需要设置这个
        footerBuilder: () => ClassicFooter(),
        // 配置默认底部指示器
        headerTriggerDistance: 80.0,
        // 头部触发刷新的越界距离
        maxOverScrollExtent: 100,
        //头部最大可以拖动的范围,如果发生冲出视图范围区域,请设置这个属性
        maxUnderScrollExtent: 0,
        // 底部最大可以拖动的范围
        enableScrollWhenRefreshCompleted: true,
        //这个属性不兼容PageView和TabBarView,如果你特别需要TabBarView左右滑动,你需要把它设置为true
        enableLoadingWhenFailed: true,
        //在加载失败的状态下,用户仍然可以通过手势上拉来触发加载更多
        hideFooterWhenNotFull: true,
        // Viewport不满一屏时,禁用上拉加载更多功能
        enableBallisticLoad: true,
        // 可以通过惯性滑动触发加载更多
        child: MaterialApp(
            locale: const Locale("zh"),
          localizationsDelegates: [
            // 这行是关键
            RefreshLocalizations.delegate,
            GlobalCupertinoLocalizations.delegate,
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
          ],
          supportedLocales: [const Locale('zh', 'CH')],

          debugShowCheckedModeBanner: false,
          title: 'Miic',
          routes: staticRoutes,
          home: IndexPage(),
        ),
      ),
    );
  }
}